-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[begin]: event_factory should cancel Close context in case of reselect #1519
[begin]: event_factory should cancel Close context in case of reselect #1519
Conversation
…eselect option Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1519 +/- ##
=======================================
Coverage ? 67.02%
=======================================
Files ? 257
Lines ? 12257
Branches ? 0
=======================================
Hits ? 8215
Misses ? 3531
Partials ? 511 ☔ View full report in Codecov by Sentry. |
@@ -101,13 +101,13 @@ func (f *eventFactoryClient) Request(opts ...Option) <-chan error { | |||
request := f.request.Clone() | |||
if o.reselect { | |||
ctx, cancel := f.ctxFunc() | |||
defer cancel() | |||
_, _ = f.client.Close(ctx, request.GetConnection(), f.opts...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,
ran the test on my side, works fine
Just a small question about the source of the issue: Am I correct in understanding that the original problem occurs because the cancel()
for Request
was run before the cancel()
for Close
, because they both use the defer
directive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. Close can use the context somewhere in its goroutine.
And this goroutine will be alive as long as this context is alive. But after the parent Close is completed, this is unnecessary and even dangerous - the goroutine can use the same data as the subsequent Request.
Therefore, before the Request, we need to complete Close call (including its goroutines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for explanation!
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1519 Commit: 836a51c Author: Artem Glazychev Date: 2023-10-16 16:32:00 +0700 Message: - event_factory should cancel Close context before Request in case of reselect option (#1519) Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Description
Chain elements in Closes can rely on the context and its timeout. Therefore, after the operation is completed, the context must be canceled.
Issue link
How Has This Been Tested?
Types of changes